package com.example.websocket.controller;

import com.example.websocket.pojo.Pyq;
import com.example.websocket.pojo.Result;
import com.example.websocket.pojo.dto.CommentDto;
import com.example.websocket.pojo.dto.LikeDto;
import com.example.websocket.pojo.dto.PublishPyqDto;
import com.example.websocket.service.PyqService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ author 韩
 * time: 2024/3/4 21:29
 */
@RestController
@RequestMapping("/pyq")
@Tag(name = "PyqController",description = "主要是关于朋友圈的一些操作")
public class PyqController {
    @Autowired
    private StringRedisTemplate redisTemplate;

    @Autowired
    private PyqService pyqService;

    @Operation(summary = "获取朋友圈列表")
    @GetMapping("/getPyqList")
    public Result getPyqList() {
        List<Pyq> pyqList = pyqService.getPyqList();
        return Result.ok(pyqList);
    }

    @Operation(summary = "点赞方法")
    @PostMapping("/addLike")
    public Result addLike(@RequestBody LikeDto likeDto) {
        boolean flag = pyqService.addLike(likeDto);
        if (flag) {
            return Result.ok();
        }else {
            return Result.error();
        }
    }

    @Operation(summary = "取消喜欢")
    @DeleteMapping("/deleteLike")
    public Result deleteLike(@RequestBody LikeDto likeDto) {
        boolean flag = pyqService.deleteLike(likeDto);
        if (flag) {
            return Result.ok();
        }else {
            return Result.error();
        }
    }

    @Operation(summary = "评论朋友圈")
    @PostMapping("/addComment")
    public Result addComment(@RequestBody CommentDto commentDto) {
        boolean flag = pyqService.addComment(commentDto);
        if (flag) {
            return Result.ok();
        }else {
            return Result.error();
        }
    }

    @Operation(summary = "发布朋友圈")
    @PostMapping("/publishPyq")
    public Result publishPyq(@RequestBody PublishPyqDto dto){

        Boolean flag = pyqService.publishPyq(dto);
        if (flag) {
            return Result.ok();
        }else {
            return Result.error();
        }
    }

}
